package model;

/**
 * FadingPiece.java
 * Purpose: presents a ball piece that fades away over time
 * 
 * @author Hans Brems
 * @version 1.0 01/12/2011
 */

import java.awt.Graphics2D;

public class FadingPiece extends BallPiece {
	private float currentHeight;
	private float currentWidth;

	/** Constructs a new fading piece */
	public FadingPiece() {
	}
	
	/** Constructs a new fading piece */
	public FadingPiece(Vector position) {
		this.position = position;
	}
	
	/** Has the piece faded completely */
	public boolean hasFaded() {
		if (this.currentHeight <= 0 || this.currentWidth <= 0) {
			return true;
		} else {
			return false;
		}
	}
	
	/** Updates the size of the piece */
	@Override
	public void update(double delta) {
		this.currentHeight -= 1f * (float)delta;
		this.currentWidth -= 1f * (float)delta;
	}
	
	/** Draws the piece */
	@Override
	public void draw(Graphics2D g) {
		// Get the piece coordinates
		int x = (int)this.position.getX();
		int y = (int)this.position.getY();
		
		// Draw the piece
		if (Piece.renderImages == true && image != null) {
			g.drawImage(BallPiece.image, x, y, (int)this.currentWidth, (int)this.currentHeight, null);
		} else {
			g.setColor(BallPiece.color);
			g.fillRect(x + 10, y + 10, (int)this.currentWidth - 20, (int)this.currentHeight - 20);
		}
	}
}